class Queue {
	constructor() {
		this.count = 0;
		this.lowstCount = 0;
		this.items = {};
	}
	enqueue(element) {//入队 向队列尾部添加一项
		this.items[this.count] = element;
		this.count++;
	}
	isEmpty() {//是否为空
		return this.count - this.lowstCount === 0;
	}
	dequeue() {//出队 移除队列的第一项并返回被移除的元素
		if (this.isEmpty()) {
			return undefined;
		}
		const result = this.items[this.lowstCount];
		delete this.items[this.lowstCount];
		this.lowstCount++;
		return result;
	}
	peek() {//返回队列中的第一个元素
		if (this.isEmpty()) {
			return undefined;
		}
		return this.items[this.lowstCount];
	}
	size() {//返回队列包含的元素个数
		return this.count - this.lowstCount;
	}
	toString() {//字符串的形式输出
		if (this.isEmpty()) {
			return "";
		}
		let objString = `${this.items[this.lowstCount]}`;
		for (let i = this.lowstCount + 1; i < this.count; i++) {
			objString = `${objString},${this.items[i]}`;
		}
		return objString;
	}
}

const q = new Queue();
//击鼓传花
function hotPotato(element, num) {
	let list = [];
	for (let item of element) {//循环入队
		q.enqueue(item);
	}
	while (q.size() > 1) {//while循环直至剩下最后一个
		for (let i = 0; i < num; i++) {
			q.enqueue(q.dequeue());
		}
		list.push(q.dequeue());
	}
	return {
		victory: q.dequeue(),
		defeat: list
	};
}
console.log(hotPotato(["a", "b", "c", "d", "e", "f"], 3));